"use strict";

//=============
// 引入程序依赖
//=============
import React, {Component} from 'react' ;
import {connect} from 'react-redux' ;
import {Link, browserHistory} from 'react-router' ;

//images
import NetworkEngine from '../../utils/NetworkEngine' ;
import UrlManager from '../../utils/UrlManager' ;
class BindingPhoneContainer extends Component {
    constructor(props) {
        super(props);
    }

    componentWillMount() {
        console.log("微博登录获取上方---------的state：",this.props.location.query.state );
        console.log("微博登录获取上方---------的code：",this.props.location.query.code );
        if(this.props.location.query.state=="weixin"){
            this.getWxInfo();
        }else if(this.props.location.query.state=="weibo"){
            this.getWbInfo();
        }else{
            this.getQQInfo();
        }

    }

    getWxInfo(){
        let urlManager = new UrlManager();
        NetworkEngine(
            "post",
            urlManager.thirdLogin(),
            {
                code : this.props.location.query.code,
                thirdType:"1"
            },
        ).then(
            data => {
                console.log("======微信信息======", data.data)
                sessionStorage.setItem("weiXinId",data.data.weiXinId)
                sessionStorage.setItem("weiXinName",data.data.weiXinName)
                sessionStorage.setItem("thirdHeadUrl",data.data.weiXinHeadUrl);
                sessionStorage.setItem("thirdType","2")
                sessionStorage.setItem("thirdName",data.data.weiXinName)
                sessionStorage.setItem("thirdNumber",data.data.weiXinId)
                sessionStorage.setItem("thirdGender",data.data.weiXinGender)
                if(data.data.ResultStatus==="1"){
                    let user=data.data.data;
                    sessionStorage.setItem("id", user.id);
                    sessionStorage.setItem("displayName", user.displayName);
                    sessionStorage.setItem("phone", user.phone);
                    sessionStorage.setItem("authenticationStatus", user.authenticationStatus);
                    sessionStorage.setItem("headUrl",user.headUrl);
                        browserHistory.push("/APP/MobileHome");
                }else{
                    browserHistory.push("/MobilePhone");
                }
            }
        ).catch(
            err => {
            }
        )
    }
    getWbInfo(){
        let urlManager = new UrlManager();
        NetworkEngine(
            "post",
            urlManager.thirdLogin(),
            {
                code : this.props.location.query.code,
                thirdType:"2"
            },
        ).then(
            data => {
                console.log("======微博信息======", data.data)
                sessionStorage.setItem("weiBoId",data.data.weiBoId)
                sessionStorage.setItem("weiBoName",data.data.weiBoName)
                sessionStorage.setItem("thirdHeadUrl",data.data.weiBoHeadUrl);
                sessionStorage.setItem("thirdType","1")
                sessionStorage.setItem("thirdName",data.data.weiBoName)
                sessionStorage.setItem("thirdNumber",data.data.weiBoId)
                sessionStorage.setItem("thirdGender",data.data.weiBoGender)
                if(data.data.ResultStatus==="1"){
                    let user=data.data.data;
                    sessionStorage.setItem("id", user.id);
                    sessionStorage.setItem("displayName", user.displayName);
                    sessionStorage.setItem("phone", user.phone);
                    sessionStorage.setItem("authenticationStatus", user.authenticationStatus);
                    sessionStorage.setItem("headUrl", user.headUrl);
                    browserHistory.push("/APP/MobileHome");
                }else{
                    browserHistory.push("/MobilePhone");
                }
            }
        ).catch(
            err => {
            }
        )
    }

    getQQInfo(){
        let urlManager = new UrlManager();
        NetworkEngine(
            "post",
            urlManager.thirdLogin(),
            {
                code : this.props.location.query.code,
                thirdType:"3"
            },
        ).then(
            data => {
                console.log("======QQ信息======", data.data)
                sessionStorage.setItem("qqId",data.data.QQId)
                sessionStorage.setItem("qqName",data.data.QQName)
                sessionStorage.setItem("thirdHeadUrl",data.data.QQHeadUrl);
                sessionStorage.setItem("thirdType","2")
                sessionStorage.setItem("thirdName",data.data.QQName)
                sessionStorage.setItem("thirdNumber",data.data.QQId)
                sessionStorage.setItem("thirdGender",data.data.QQGender)
                if(data.data.ResultStatus==="1"){
                    let user=data.data.data;
                    sessionStorage.setItem("id", user.id);
                    sessionStorage.setItem("displayName", user.displayName);
                    sessionStorage.setItem("phone", user.phone);
                    sessionStorage.setItem("authenticationStatus", user.authenticationStatus);
                    sessionStorage.setItem("headUrl",user.headUrl);

                        browserHistory.push("/APP/MobileHome");
                }else{
                    browserHistory.push("/MobilePhone");
                }
            }
        ).catch(
            err => {
            }
        )
    }
    render() {
        return (
            <div></div>
        )
    }
}
const BindingPhone = connect()(BindingPhoneContainer) ;

export { BindingPhone as default } ;
